#!/usr/bin/env bash
################################################################################
# Test objective: check that an persistent VALE port opened with the exclusive
#                 flag can't be opened again.
################################################################################
source test_lib

parse_send_recv_arguments "$@"
verbosity="${verbosity:-}"

bridge="vale0"
port="v0"

create_vale_persistent_port "$port"
attach_to_vale_bridge "$bridge" "$port"

# We open the persistent port with the exclusive flag from the file descriptor.
functional $verbosity -i "${bridge}:${port}/x"
check_success $? "exclusive-open ${bridge}:${port}/x"

# Then we open the same interface again, this time without requesting it from
# the file descriptor, causing a second nm_open().
functional $verbosity -I "${bridge}:${port}"
check_failure $? "no-open ${bridge}:${port}"

# Check that another exclusive open request fails.
functional $verbosity -I "${bridge}:${port}/x"
check_failure $? "no-open ${bridge}:${port}/x"
